import time
from time import sleep
from common.loger_handler import mylog
from page_element.key import PageKey


class page_set1(PageKey):
    """飞行设置"""

    def set_001_001(self, height, distance):
        """高度，限制距离测试"""
        self.iv_zorroRealcontrol_set.click()
        self.driver(resourceId="com.gdu.pro2:id/et_height_limit").clear_text()
        self.driver(resourceId="com.gdu.pro2:id/et_height_limit").send_keys(height)     # 限制高度
        self.driver(resourceId="com.gdu.pro2:id/et_distance_limit").click()
        time.sleep(2)
        ts = self.driver.xpath('//*[@text="同意"]')
        if ts.exists:
            ts.click()
        else:
            pass
        self.driver(resourceId="com.gdu.pro2:id/et_distance_limit").clear_text()
        self.driver(resourceId="com.gdu.pro2:id/et_distance_limit").send_keys(distance)   # 限制距离
        time.sleep(1)
        self.driver.press("back")
        self.driver.press("back")
        time.sleep(1)
        masgi = self.driver.xpath('//*[@resource-id="com.gdu.pro2:id/tv_shang_lat2lon_text_info"]').get_text()
        masgi_list = masgi.split(",")
        zxgd = masgi_list[7]
        zxjl = masgi_list[6][10:]
        mylog.info(F"--------{zxgd}---------{zxjl}")

    def set_001_002(self, a, b):
        """高度，限制开关测试-----全开"""
        sleep(2)
        self.iv_zorroRealcontrol_set.click()
        sleep(1)
        if self.driver(resourceId="com.gdu.pro2:id/iv_switch_limit_height").info['selected'] == a:
            pass
        else:
            self.driver(resourceId="com.gdu.pro2:id/iv_switch_limit_height").click()     # 限制高度开关
            self.driver(resourceId="com.gdu.pro2:id/dialog_btn_sure").click()
        if self.driver(resourceId="com.gdu.pro2:id/iv_switch_limit_distance").info['selected'] == b:
            pass
        else:
            self.driver(resourceId="com.gdu.pro2:id/iv_switch_limit_distance").click()   # 限制距离开关
        time.sleep(1)
        self.driver.press("back")
        masgi = self.driver.xpath('//*[@resource-id="com.gdu.pro2:id/tv_shang_lat2lon_text_info"]').get_text()
        masgi_list = masgi.split(",")
        zxgd = masgi_list[7]
        zxjl = masgi_list[6][10:]
        mylog.info(F"--------{zxgd}---------{zxjl}")


    def set_001_003(self, height, speed):
        """返航高度，速度"""
        self.iv_zorroRealcontrol_set.click()
        time.sleep(1)
        self.driver(resourceId="com.gdu.pro2:id/et_height").clear_text()
        self.driver(resourceId="com.gdu.pro2:id/et_height").send_keys(height)            # 返航高度
        self.driver.press("back")
        self.driver(resourceId="com.gdu.pro2:id/et_back_speed").clear_text()
        self.driver(resourceId="com.gdu.pro2:id/et_back_speed").send_keys(speed)        # 返航速度
        self.driver.press("back")
        self.driver.press("back")


    def set_001_004(self):
        """失联行为"""
        self.iv_zorroRealcontrol_set.click()
        time.sleep(1)
        self.driver(resourceId="com.gdu.pro2:id/ov_out_of_control").click()        # 失联行为
        self.driver(resourceId="com.gdu.pro2:id/option_tv", text="悬停").click()
        self.driver(resourceId="com.gdu.pro2:id/ov_return_home").click()           # 返航行为
        self.driver.xpath('//*[@text="HOME点上方悬停"]').click()
        self.driver.press("back")



